package com.kb.shop.controller;

import com.kb.order.pojo.OrderComment;
import com.kb.shop.pojo.ShopCollect;
import com.kb.shop.service.IOrderCommentService;
import com.kb.shop.service.IshopCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/comment")
@ResponseBody
public class OrderCommentController {
    @Autowired
    private IOrderCommentService iOrderCommentService;
    @Autowired
    private IshopCollectService ishopCollectService;

    @GetMapping("/lookComment")
    public List<OrderComment> LookComment(Integer shopId){
        List<OrderComment> list=iOrderCommentService.selectOne(shopId);
        System.out.println(list);
        return list;
    }

    @RequestMapping("lookStart")
    public String lookStart(Integer shopId){
        try {
            ShopCollect collect = new ShopCollect();
            collect.setShop_Id(new Long(shopId));
            collect.setUser_Id(new Long(1));
            List<ShopCollect> shopCollectList = ishopCollectService.select(collect);
            if(shopCollectList.size()!=0){
                return "1";
            }else{
                return "0";
            }
        }catch (Exception e){
            e.printStackTrace();
            return "0";
        }
    }

    @RequestMapping("/start")
    public String start(Integer shopId){
        try {
            ShopCollect collect = new ShopCollect();
            collect.setShop_Id(new Long(shopId));
            collect.setUser_Id(new Long(1));
            ishopCollectService.insert(collect);
            return "1";
        }catch (Exception e){
            e.printStackTrace();
            return "0";
        }
    }

    @RequestMapping("/upStart")
    public String upStart(Integer shopId){
        try {
            ShopCollect collect = new ShopCollect();
            collect.setShop_Id(new Long(shopId));
            collect.setUser_Id(new Long(1));
            ishopCollectService.delete(collect);
            return "1";
        }catch (Exception e){
            e.printStackTrace();
            return "0";
        }
    }

}
